package com.mdz.nc.Controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mdz.nc.Entity.Sbbfb;
import com.mdz.nc.Mapper.SbbfbMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.LocalDate;
import java.time.Period;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 孟德志
 * @since 2020-07-09
 */
@Controller
@RequestMapping("/nc/sbbfb")
public class SbbfbController {
    @Autowired
    private SbbfbMapper sbbfbMapper;

    @ResponseBody
    @RequestMapping(value = "/insertbaof", method = RequestMethod.POST)
    public int insertbaof(Sbbfb sbbfb) {
        LocalDate today = LocalDate.now();
        sbbfb.setBfrq(today);
        String[] bs=sbbfb.getGmrq().split("-");
        LocalDate birthday=LocalDate.of(Integer.valueOf(bs[0]),Integer.valueOf(bs[1]),Integer.valueOf(bs[2]));
        sbbfb.setBfbs("1");
        sbbfb.setBfshuom(sbbfb.getSbbh()+"设备,在"+today+"报废，报废申请编号为"+sbbfb.getBfsqbh());
        Period p = Period.between(birthday, today);
//        System.out.printf("年龄 : %d 年 %d 月 %d 日", p.getYears(), p.getMonths(), p.getDays());
        int ye= p.getYears()+1;
        sbbfb.setBfyuany(sbbfb.getSbbh()+"设备,以使用"+ye+"年了，以无维修价值了，故报废");
        return sbbfbMapper.insert(sbbfb);
    }

    @ResponseBody
    @RequestMapping(value = "/getsbbf",method = RequestMethod.GET)
    public List<Sbbfb> getsbbf(){
        List<Sbbfb> sbbfbs=sbbfbMapper.selectList(new QueryWrapper<Sbbfb>().eq("bfbs","1"));
        return sbbfbs;
    }
}